package com.czl.module_main.adapter

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.CommunityResponseBean
import com.czl.module_main.R
import com.czl.module_main.databinding.ItemCommunityBinding
import com.czl.module_main.fragment.HomeFragment

class CommunityAdapter(private val fragment: HomeFragment) :
    BaseQuickAdapter<CommunityResponseBean.Record, BaseDataBindingHolder<ItemCommunityBinding>>(
        R.layout.item_community
    ) {

    override fun convert(holder: BaseDataBindingHolder<ItemCommunityBinding>, item: CommunityResponseBean.Record) {
        holder.dataBinding?.apply {
            viewModel = item
            adapter = this@CommunityAdapter
            executePendingBindings()
        }
    }

    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is CommunityResponseBean.Record){
            fragment.startContainerActivity(
                AppConstants.Router.Activities.F_ACTIVITIES_DETAIL,
                Bundle().apply {
                    putString(
                        AppConstants.BundleKey.ACTIVITY_ID,
                        it.id.toString()
                    )
                })
        }
    })
}